package com.tutorial;

import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map;

import spark.Request;
import spark.Response;
import spark.Route;
import spark.Spark;
import freemarker.template.Configuration;
import freemarker.template.Template;

public class HelloWorldSparkFreemarkerStyle {

	public static void main(String[] args) {
		
		final Configuration config = new Configuration();
		config.setClassForTemplateLoading(HelloWorldSparkFreemarkerStyle.class, "/");
		
		Spark.get(new Route("/") {			
			@Override
			public Object handle(Request request, Response response) {
				Template template;
				Map<String, String> map = new HashMap<String, String>();
				map.put("msg", "HelloWorldSparkFreemarkerStyle");
				
				StringWriter writer = new StringWriter();
				try {
					template = config.getTemplate("hello.ftl");
					template.process(map, writer);
				} catch (Exception e) {
					halt(500);
					e.printStackTrace();
				}

				return writer;
			}
		});
	}

}
